export default function ({ graph, showTooltip, hideTooltip, clickNode }) {
  function clickMoreLabel(e) {
    const { item } = e
    const data = graph.findDataById(item.getID())
    if (data?.hiddenChildren?.length > 0) {
      const parentNode = item.getNeighbors('source')[0]
      const parentData = graph.findDataById(parentNode.getID())
      parentData.children.splice(parentData.children.length - 1, 1)
      parentData.children = parentData.children.concat(data.hiddenChildren)
      graph.updateChildren(parentData.children, parentNode.getID())
    }
  }

  graph.on('node:click', function (e) {
    if (e.item.getModel().type === 'more-node') {
      clickMoreLabel(e)
    } else if (e.target.get('name') !== 'collapse-icon') {
      clickNode(e)
    }
  })

  graph.on('node:mouseenter', function (e) {
    showTooltip(e)
  })
  graph.on('node:mouseleave', function (e) {
    hideTooltip(e)
  })

  // 防止用户右键下载图片，因为下载的图片不带水印
  graph.on('contextmenu', function (e) {
    e.preventDefault()
  })
}
